<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>


<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">



  <meta name="description" content="在Windows平台下搭建Git私有服务器"/>




  <meta name="keywords" content="git, Tao's Blog" />










  <link rel="alternate" href="/default" title="Tao's Blog">




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=2.6.0" />



<link rel="canonical" href="http://yoursite.com/2018/02/27/在Windows平台下搭建Git私有服务器/"/>


<link rel="stylesheet" type="text/css" href="/css/style.css?v=2.6.0" />



  <link rel="stylesheet" type="text/css" href="/lib/fancybox/jquery.fancybox.css" />




  



  <script id="baidu_push">
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>









    <title> 在Windows平台下搭建Git私有服务器 - Tao's Blog </title>
  </head>

  <body><div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/." class="logo">Tao's Blog</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>

<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    
      <a href="/">
        <li class="mobile-menu-item">
          
          
            首页
          
        </li>
      </a>
    
      <a href="/archives/">
        <li class="mobile-menu-item">
          
          
            归档
          
        </li>
      </a>
    
  </ul>
</nav>

    <div class="container" id="mobile-panel">
      <header id="header" class="header"><div class="logo-wrapper">
  <a href="/." class="logo">Tao's Blog</a>
</div>

<nav class="site-navbar">
  
    <ul id="menu" class="menu">
      
        <li class="menu-item">
          <a class="menu-item-link" href="/">
            
            
              首页
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/archives/">
            
            
              归档
            
          </a>
        </li>
      
    </ul>
  
</nav>

      </header>

      <main id="main" class="main">
        <div class="content-wrapper">
          <div id="content" class="content">
            
  
  <article class="post">
    <header class="post-header">
      <h1 class="post-title">
        
          在Windows平台下搭建Git私有服务器
        
      </h1>

      <div class="post-meta">
        <span class="post-time" title="2018-02-27T10:18:07Z">
          2018-02-27
        </span>
        
          <div class="post-category">
            
              <a href="/categories/git/">git</a>
            
          </div>
        
        
      </div>
    </header>

    
    
  <div class="post-toc" id="post-toc">
    <h2 class="post-toc-title">文章目录</h2>
    <div class="post-toc-content">
      <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#一、前言"><span class="toc-text">一、前言</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#二、步骤"><span class="toc-text">二、步骤</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-安装Java环境"><span class="toc-text">1. 安装Java环境</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-安装Git"><span class="toc-text">2. 安装Git</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#3-安装gitblit"><span class="toc-text">3. 安装gitblit</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4-运行gitblit"><span class="toc-text">4. 运行gitblit</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#5-以Windows-Service方式启动gitblit"><span class="toc-text">5. 以Windows Service方式启动gitblit</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#三、总结"><span class="toc-text">三、总结</span></a></li></ol>
    </div>
  </div>


    <div class="post-content">
      
        <h4 id="一、前言"><a href="#一、前言" class="headerlink" title="一、前言"></a>一、前言</h4><p>&#8194;&#8194;&#8194;&#8194;在正式开始之前，简单的聊几句版本控制工具,常用的包括CVS、SVN、Git、Mecurial等等，CVS太老Mecurial用的人少就不说了，剩下的两个才是常用的，关于他们的详细区别见<a href="https://www.cnblogs.com/dazhidacheng/p/7478438.html" target="_blank" rel="noopener">这里</a>, 因为SVN的安全控制和权限管理更好， 我们公司一直都在用它, 不仅仅是代码还有文档、日报、设计图等等都托管在上面想来是不太可能离得开了。但是每次项目上线或在之后的维护中多多少少中会出问题，我就想用Git来管理代码,其他文档类的还用SVN会不会好点。不管是Git还是SVN都需要代码仓库啊，想想Github是裸奔的，码云有5个成员限制，泪流满面啊，还是老老实实的搭个私服吧，于是有了本篇文章。</p>
<h4 id="二、步骤"><a href="#二、步骤" class="headerlink" title="二、步骤"></a>二、步骤</h4><p>环境：Windows Server 2012</p>
<h5 id="1-安装Java环境"><a href="#1-安装Java环境" class="headerlink" title="1. 安装Java环境"></a>1. 安装Java环境</h5><p>下载JDK并安装，要求jdk1.7以后，安装过程自行百度，如果已安装看下一步。</p>
<h5 id="2-安装Git"><a href="#2-安装Git" class="headerlink" title="2. 安装Git"></a>2. 安装Git</h5><p>自行百度，算了我直接贴网址，<a href="https://jingyan.baidu.com/article/9f7e7ec0b17cac6f2815548d.html" target="_blank" rel="noopener">点击跳转</a>，顺便送一份大神写的<a href="https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000" target="_blank" rel="noopener">Git教程</a>。</p>
<h5 id="3-安装gitblit"><a href="#3-安装gitblit" class="headerlink" title="3. 安装gitblit"></a>3. 安装gitblit</h5><p>下载gitblit(<a href="http://www.gitblit.com/" target="_blank" rel="noopener">官网地址</a>), 最新版是16年更新的1.8.0，它要求JDK在1.7以上。直接解压到本地磁盘，例如我的是K:\git\gitblit，CD到data目录下，编辑defaults.properties文件，查找并修改以下几个变量的值，你也可以在gitblit.properties最下方添加这些键值对，会覆盖默认值。</p>
<pre><code>    git.repositoriesFolder = K:\git\repositories
server.httpPort = 10101
server.httpBindInterface = 192.168.1.100
server.httpsBindInterface = localhost 
</code></pre><p>第一个值是代码仓库文件夹，第二个是端口号，第三、四是主机，如果你想外网可访问，请把最后两个变量的值换成您的静态IP地址。</p>
<h5 id="4-运行gitblit"><a href="#4-运行gitblit" class="headerlink" title="4. 运行gitblit"></a>4. 运行gitblit</h5><p>返回到上级目录也就是根目录，双击运行gitblit.cmd，此时在浏览器里输入 <a href="http://192.168.1.100:10101/" target="_blank" rel="noopener">http://192.168.1.100:10101/</a> 就可以访问了，默认的管理员账户和密码都是admin， 页面是这样地<img src="http://p2eetui5w.bkt.clouddn.com/18-2-27/57322762.jpg" alt="image"></p>
<h5 id="5-以Windows-Service方式启动gitblit"><a href="#5-以Windows-Service方式启动gitblit" class="headerlink" title="5. 以Windows Service方式启动gitblit"></a>5. 以Windows Service方式启动gitblit</h5><p>回到根目录下，编辑器打开installService.cmd 文件</p>
<ul>
<li><p>根据操作系统位数修改ARCH</p>
<pre><code>  32位系统：SET ARCH=x86
64位系统：SET ARCH=amd64 
</code></pre></li>
<li><p>添加 CD 为程序目录 </p>
<pre><code>SET CD=K:\git\gitblit   (你的目录) 
</code></pre></li>
<li><p>修改StartParams里的启动参数，设为空就好了</p>
</li>
<li>保存后右键以管理员的身份运行installService.cmd</li>
<li>此时Run里面执行services.msc打开系统服务是不是发现了gitblit</li>
</ul>
<h4 id="三、总结"><a href="#三、总结" class="headerlink" title="三、总结"></a>三、总结</h4><p>在Windows平台下搭建Git私有服务器就可以使用了，对系统的操作上和Github差不多，还要靠大家自己尝试。有个坑需要大家注意下，在使用ssh协议clone时，碰到了这个错误  <span style="color:red;">fatal: ssh variant ‘simple’ does not support setting port</span>， 这是因为我的git版本升到了2.16.0了，原因见<a href="https://tortoisegit.org/docs/tortoisegit/tgit-ssh-howto.html" target="_blank" rel="noopener">这里</a>，解决办法也非常简单，就是在环境变量里添加GIT_SSH_VARIANT = ssh！如果有新的东西，以后会不定时更新。</p>

      
    </div>

    
      
      

  <div class="post-copyright">
    <p class="copyright-item">
      <span>原文作者: </span>
      <a href="http://yoursite.com">jiangore</a>
    </p>
    <p class="copyright-item">
      <span>原文链接: </span>
      <a href="http://yoursite.com/2018/02/27/在Windows平台下搭建Git私有服务器/">http://yoursite.com/2018/02/27/在Windows平台下搭建Git私有服务器/</a>
    </p>
    <p class="copyright-item">
      <span>许可协议: </span>
      
      <a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/" target="_blank">知识共享署名-非商业性使用 4.0 国际许可协议</a>
    </p>
  </div>



      
      
    

    
      <footer class="post-footer">
        
          <div class="post-tags">
            
              <a href="/tags/git/">git</a>
            
          </div>
        
        
        
  <nav class="post-nav">
    
    
      <a class="next" href="/2018/02/05/hello-world/">
        <span class="next-text nav-default">Hello World</span>
        <span class="prev-text nav-mobile">下一篇</span>
        <i class="iconfont icon-right"></i>
      </a>
    
  </nav>

      </footer>
    

  </article>


          </div>
          
  <div class="comments" id="comments">
    
  </div>


        </div>
      </main>

      <footer id="footer" class="footer">

  <div class="social-links">
    
      
        
          <a href="mailto:your@email.com" class="iconfont icon-email" title="email"></a>
        
      
    
      
    
      
    
      
    
      
    
      
    
      
    
      
    
      
    
      
    
      
    
      
    
      
    
    
    
      
      <a href="/atom.xml" class="iconfont icon-rss" title="rss"></a>
    
  </div>


<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://hexo.io/">Hexo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 - 
    <a class="theme-link" href="https://github.com/ahonn/hexo-theme-even">Even</a>
  </span>

  <span class="copyright-year">
    
    &copy; 
     
      2017 - 
    
    2018

    <span class="heart">
      <i class="iconfont icon-heart"></i>
    </span>
    <span class="author">jiangore</span>
  </span>
</div>

      </footer>

      <div class="back-to-top" id="back-to-top">
        <i class="iconfont icon-up"></i>
      </div>
    </div>

    
  
  

  



    
  





  
    <script type="text/javascript" src="/lib/jquery/jquery-3.1.1.min.js"></script>
  

  
    <script type="text/javascript" src="/lib/slideout/slideout.js"></script>
  

  
    <script type="text/javascript" src="/lib/fancybox/jquery.fancybox.pack.js"></script>
  


    <script type="text/javascript" src="/js/src/even.js?v=2.6.0"></script>
<script type="text/javascript" src="/js/src/bootstrap.js?v=2.6.0"></script>
<script type="text/javascript" src="/js/static/jquery.prettydate.js?v=2.6.0"></script>
<script type="text/javascript" src="/js/static/post.js?v=2.6.0"></script>

  </body>
</html>
